package com.fanshuai.queue.priority;

import com.fanshuai.heap.MaxHeap;
import com.fanshuai.queue.Queue;

/**
 * 优先队列，基于堆实现
 * @param <E>
 */
public class HeapPriorityQueue<E extends Comparable<E>> implements Queue<E> {
    private MaxHeap<E> heap;

    public HeapPriorityQueue(int maxSize) {
        heap = new MaxHeap<E>(maxSize);
    }

    @Override
    public int size() {
        return heap.size();
    }

    @Override
    public boolean isEmpty() {
        return heap.isEmpty();
    }

    @Override
    public boolean isFull() {
        return heap.isFull();
    }

    @Override
    public void enqueue(E data) {
        heap.add(data);
    }

    @Override
    public E dequeue() {
        return heap.pop();
    }

    @Override
    public E peek() {
        return heap.peek();
    }
}
